﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace MyCommon.Configuration
{
    /// <summary>
    /// 配置文件的自定义Section类型 --郭旭东
    /// </summary>
    public class SampleSection : ConfigurationSection
    {
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("defaultName")]
        public string DefaultName
        {
            get { return (string)this["defaultName"]; }
            set { this["defaultName"] = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("settings", IsDefaultCollection = true)]
        [ConfigurationCollection(typeof(SampleSettings), AddItemName = "add")]
        public ConfigurationSettingsCollection<SampleSettings> Settings
        {
            get
            {
                return (ConfigurationSettingsCollection<SampleSettings>)this["settings"];
            }
        }
    }

    /// <summary>
    /// 配置文件SettingsCollection中的项 --郭旭东
    /// </summary>
    [ConfigurationSettingsKey("Name")]
    public class SampleSettings : ConfigurationElement
    {
        /// <summary>
        /// 
        /// </summary>
        public SampleSettings()
        {
        }
        /// <summary>
        /// 构造SampleSettings
        /// </summary>
        /// <param name="name"></param>
        /// <param name="studentCount"></param>
        public SampleSettings(string name, int studentCount)
            : this()
        {
            Name = name;
            StudentCount = studentCount;
        }
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("name", IsKey = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("studentCount")]
        public int StudentCount
        {
            get { return (int)this["studentCount"]; }
            set { this["studentCount"] = value; }
        }
    }
}
